package com.dawn.module.hospital.controller.admin.refund;

import com.dawn.framework.common.pojo.CommonResult;
import com.dawn.module.hospital.controller.admin.refund.vo.RefundReqVO;
import com.dawn.module.hospital.controller.admin.refund.vo.SearchReqVO;
import com.dawn.module.hospital.enums.ErrorCodeConstants;
import com.dawn.module.hospital.service.RefundService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: cnsu-cmh
 * @time: 2024/10/16 12:10
 */
@Tag(name = "退费相关 管理后台 - bh")
@RestController
@RequestMapping("/bh/refund")
@Validated
public class RefundController {

    @Autowired
    private RefundService refundService;

    @Operation(summary = "异常退费订单记录")
    @GetMapping("/query")
    @PreAuthorize("@ss.hasPermission('bh:refund:query')")
    public CommonResult abnormalRefundQuery(@Valid SearchReqVO reqVO){

        if("QAC".equals(reqVO.getOrderType())) {
            if (StringUtils.isEmpty(reqVO.getOrderNo())) {
                return CommonResult.error(ErrorCodeConstants.BH_ERROR.getCode(),"请输入订单号-orderNo");
            }
            List<Map<String, String>> list = refundService.getQacAbnormalOrderList(reqVO.getOrderNo());
            return CommonResult.success(list);
        } else {
            List<HashMap<String, String>> list = refundService.getAbnormalOrderList(reqVO);
            return CommonResult.success(list);
        }
    }

    @Operation(summary = "异常退费订单记录")
    @PostMapping("/dorefund")
    @PreAuthorize("@ss.hasPermission('bh:refund:dorefund')")
    public CommonResult abnormalRefund(@Valid RefundReqVO reqVO){
        CommonResult result = refundService.abnormalRefund(reqVO);
        return result;
    }
}
